package test.test_7_11;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo02 {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("a.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("a.txt",true);

        byte[] arr = fileInputStream.readAllBytes();
        String str = new String(arr);
        System.out.println(str);

        int oddNum = 0;
        int evenNum = 0;

        for (int i = 0; i < str.length(); i++) {
            int num = Integer.parseInt(str.charAt(i) + "");
            if (num % 2 == 0) {
                evenNum++;
            } else {
                oddNum++;
            }
        }
//        System.out.println("偶数个数："+evenNum);
//        System.out.println("奇数个数："+oddNum);

        String str1 ="偶数个数："+evenNum;
        String str2 = "奇数个数："+oddNum;
        fileOutputStream.write("\r\n".getBytes());
        fileOutputStream.write(str1.getBytes());
        fileOutputStream.write("\r\n".getBytes());
        fileOutputStream.write(str2.getBytes());

        fileInputStream.close();
        fileOutputStream.close();
    }


}
